class DateUtil {
  formatDate(num: number): string {
    let date = new Date(num)
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()
    let m = month < 10 ? '0' + month : month
    let d = day < 10 ? '0' + day : day
    let res = `${year}-${m}-${d}`
    return res
  }

  beginTimeOfDay(date: Date) {
    let d = new Date(date.getFullYear(), date.getMonth(), date.getDate())
    return d.getTime()
  }

  getFullYearFromDatePickRes(year: number, month: number, day: number) {
    let m = month < 10 ? '0' + month : month
    let d = day < 10 ? '0' + day : day
    return `${year}-${m}-${d}`
  }

  getMonthDayFromDatePickRes(month: number, day: number) {
    let m = month < 10 ? '0' + month : month
    let d = day < 10 ? '0' + day : day
    return { month: m, day: d }
  }

  getYearMonthDay(_month?: number, _day?: number, _year?: number) {
    let date = new Date()
    let year = _year ? _year : date.getFullYear()
    let month = _month ? _month : date.getMonth()
    let day = _day ? _day : date.getDate()

    month = month + 1
    let m = month < 10 ? '0' + month : month
    let d = day < 10 ? '0' + day : day
    return { month: m, day: d, year: year }
  }

  getRealMonth(date: string): number {
    let d = new Date(date)
    let month = d.getMonth() + 1
    let m = month < 10 ? '0' + month : month
    return parseInt(m.toString());
  }
}

let dateUtil = new DateUtil()

export default dateUtil as DateUtil